﻿var ROOT_PATH = $("#root_path").val();   //get base_url

var emailcheck = false;
//-------------------------------------email check----------------------------------
// display error message if email is invalid
function emailErrMsg(msg){
	$("#email").attr("class", "wrong"); 
	$("#emailTip").text(msg).show();	
}


//check if email on valid format
function emailFormatCheck(email){
    var reg = new RegExp("^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
    return reg.test(email);	
}

//check if email are valid
function emailCheck(){
	var email =$.trim($("#email").val()).toLowerCase();   
    if (email.length <= 0) {  //check if email is empty
    	emailErrMsg("邮箱地址不能为空！");
    	return false;
    }
    else {
    	if (!emailFormatCheck(email)){
        	emailErrMsg("Email格式不正确！");
        	return false;
    	}
    }
    return true;
}
//--------------------------- processing --------------------------
function psubmit() {
    if ($("input[class*='wrong']").length > 0) return;
    
    if ($.trim($("#username").val()).length <= 0) {
    	  $("#username").attr("class", "wrong"); 
    	  $("#nameTip").show(); 
    	  return; 
    }
    
    if (!emailCheck()) return;   //check email 

    if (!codeBlur()) return;       //check captcha code
    document.forms[0].submit();
}

function codeBlur() {
    if ($.trim($("#forgotCode").val()).length <= 0) { 
    	$("#forgotCode").attr("class", "verification wrong"); 
    	$("#checkcodetip").attr("class", "red").text("请输入验证码"); 
    	return false; 
    }
    else { 
    	$("#forgotCode").attr("class", "verification"); 
    	$("#checkcodetip").attr("class", "").text("点击图片刷新验证码"); 
    	return true; 
    }
}

function enter(e) {
    if (e.keyCode == 13) {
        psubmit();
        return false;
    }
}



